﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data.SqlClient;
using System.Data;
using System.Collections;
using System.Drawing;
using System.Drawing.Drawing2D;
using DataAccess;


namespace BusinessLogic
{
    public static class HangHoaTheoMaNhomHangHoa 
    {
        public static Entities.HangHoa[] SelectHangHoaTheoNhomHang(Entities.HangHoa giatri)
        {
            Entities.HangHoa[] list = null;
            try
            {
                string sql = Common.Constants.HangHoaTheoMaNhomHangHoa.sp_Select_HangHoaTheoNhomHang;
                SqlConnection cn = DataAccess.Connection.OpenConnection();
                SqlCommand cmd = new SqlCommand(sql, cn);
                cmd.Parameters.Add(Common.Constants.HangHoaTheoMaNhomHangHoa.MaNhomHang, SqlDbType.VarChar, 50).Value = giatri.MaHangHoa;
                SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                ArrayList arr = new ArrayList();
                while (dr.Read())
                {
                    Entities.HangHoa row = new Entities.HangHoa();
                    row.HangHoaID = int.Parse(dr[Common.Constants.HangHoa.HangHoaID].ToString());
                    row.MaHangHoa = dr[Common.Constants.HangHoa.MaHangHoa].ToString();
                    row.TenHangHoa = dr[Common.Constants.HangHoa.TenHangHoa].ToString();
                    row.MaNhomHang = dr[Common.Constants.HangHoa.MaNhomHang].ToString();
                    row.TenNhomHang = dr[Common.Constants.HangHoa.TenNhomHang].ToString();
                    row.MaDonViTinh = dr[Common.Constants.HangHoa.MaDonViTinh].ToString();
                    row.TenDonViTinh = dr[Common.Constants.HangHoa.MaDonViTinh].ToString();
                    row.GiaNhap = dr[Common.Constants.HangHoa.GiaNhap].ToString();
                    row.GiaBanBuon = dr[Common.Constants.HangHoa.GiaBanBuon].ToString();
                    row.GiaBanLe = dr[Common.Constants.HangHoa.GiaBanLe].ToString();
                    row.MaThue = dr[Common.Constants.HangHoa.MaThue].ToString();
                    row.GiaTriThue = dr[Common.Constants.HangHoa.GiaTriThue].ToString();
                    row.MucDatHang = dr[Common.Constants.HangHoa.MucDatHang].ToString();
                    row.MucTonToiThieu = dr[Common.Constants.HangHoa.MucTonToiThieu].ToString();
                    row.LinkImage = dr[Common.Constants.HangHoa.LinkImage].ToString();
                    row.GhiChu = dr[Common.Constants.HangHoa.GhiChu].ToString();
                    row.Deleted = Boolean.Parse(dr[Common.Constants.HangHoa.Deleted].ToString());
                    arr.Add(row);
                }

                int n = arr.Count;
                if (n == 0) { list = null; }
                list = new Entities.HangHoa[n];
                for (int i = 0; i < n; i++)
                {
                    list[i] = (Entities.HangHoa)arr[i];
                }
                cmd.Connection.Dispose();
                cn.Close();
                DataAccess.Connection.CloseConnection();
            }
            catch (Exception ex)
            { string s = ex.Message.ToString(); list = null; }
            return list;
        }


    }
}
